package dang.action.order;

import java.io.UnsupportedEncodingException;
import java.util.List;

import dang.action.DangAction;
import dang.action.cart.Cart;
import dang.action.cart.CartItem;
import dang.common.CookieUtil;
public class OrderInfoAction extends DangAction {
	private List<CartItem> items;
	private int totalPrice;
	public String execute() throws UnsupportedEncodingException {
		Cart cart = (Cart) session.get("cart");
		if(cart!=null){
			items=cart.list();
		}else{
			cart=new Cart();
			String cartInfoId=(String) session.get("cartInfoId").toString();
			String cartInfo=CookieUtil.getCookie("cartInfo"+cartInfoId,request);
			items=cart.load(cartInfo);
			session.put("cart", cart);
		}
		return "success";
	}
	public List<CartItem> getItems() {
		return items;
	}
	public void setItems(List<CartItem> items) {
		this.items = items;
	}
	public int getTotalPrice() {
		for (CartItem item : items) {
			totalPrice+=item.getQty()*item.getProduct().getDang_price()*(item.getProduct().isDeleted()?0:1);
		}
		return totalPrice;
	}
	public void setTotalPrice(int totalPrice) {
		this.totalPrice = totalPrice;
	}
}
